﻿using System.Linq;
using VideoServices.Domain.Entities;

namespace VideoServices.Domain.DAL
{
    public interface IWarehouseDataAccess
    {
        /// <summary>
        /// Gets the warehouse by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        Warehouse GetWarehouseById(int id);

        /// <summary>
        /// Creates the warehouse.
        /// </summary>
        /// <param name="newWarehouse">The new warehouse.</param>
        /// <returns></returns>
        Warehouse CreateWarehouse(Warehouse newWarehouse);
    }

    public class WarehouseDataAccess : BaseDataAccess, IWarehouseDataAccess
    {
        /// <summary>
        /// Gets the warehouse by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Warehouse GetWarehouseById(int id)
        {
            return DataContext.Warehouses.SingleOrDefault(s => s.id == id);
        }

        /// <summary>
        /// Creates the warehouse.
        /// </summary>
        /// <param name="newWarehouse">The new warehouse.</param>
        /// <returns></returns>
        public Warehouse CreateWarehouse(Warehouse newWarehouse)
        {
            DataContext.Warehouses.InsertOnSubmit(newWarehouse);
            DataContext.SubmitChanges();
            return newWarehouse;
        }
    }
}
